package com.cy.ppj.comm.config;

import com.aliyun.oss.OSSClient;
import com.cy.ppj.comm.properties.OssProperties;
import com.cy.ppj.comm.utils.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;

/**
 * @description: Oss配置
 * @author: Ocean
 * @create: 2018-08-09 10:04
 **/
@Slf4j
@Configuration
public class AliyunConfig {

    @Bean
    public OSSClient ossClient(OssProperties ossProperties) {
        OSSClient ossClient = new OSSClient(ossProperties.getEndpoint(), ossProperties.getAccessKeyId(), ossProperties.getSecretAccessKey());
        return ossClient;
    }

    @PreDestroy
    public void destory() {
        log.info("正在关闭Oss...");
        OSSClient ossClient = SpringContextUtils.getBean(OSSClient.class);
        ossClient.shutdown();
        log.info("已关闭");
    }
}
